<template>
  <el-dialog :title="`${form.patRouteId ? '修改' : '添加'}巡更路线`" :visible.sync="show" :close-on-click-modal="false" :show-close="!btnLoading" width="500px" @closed="$refs.form.resetFields()">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item prop="projectId" class="hide" />
      <el-form-item prop="patRouteId" class="hide" />
      <el-form-item label="路线名称" prop="routeName"><el-input v-model.trim="form.routeName" placeholder="请输入路线名称" :maxlength="100" /></el-form-item>
      <el-form-item label="按顺序巡更" prop="isOrdered"><el-switch v-model="form.isOrdered" :active-value="1" :inactive-value="0" /></el-form-item>
      <el-form-item label="备注" prop="remark"><el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :maxlength="255" /></el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="btnSubmit">确 定</el-button>
      <el-button :disabled="btnLoading" @click="show = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
// 添加或修改巡更路线
import { nameRule } from '@/utils/validate'
import { editFormMixin } from '@/utils/mixin'
import { addRoute, setRoute } from '@/api/cq/patrol'
export default {
  mixins: [editFormMixin],
  data() {
    return {
      primaryKey: 'patRouteId',
      addApi: addRoute,
      updateApi: setRoute,
      form: {
        projectId: '',
        patRouteId: '',
        routeName: '',
        isOrdered: 1,
        remark: ''
      },
      rules: {
        routeName: [{ required: true, message: '请输入路线名称' }, nameRule]
      }
    }
  }
}
</script>
